package com.example.qicao.myapplication;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;

import com.orhanobut.logger.AndroidLogAdapter;
import com.orhanobut.logger.Logger;

public class MainActivity extends AppCompatActivity
    implements RageComicListFragment.OnRageComicSelected {

  @Override
  protected void onCreate(Bundle savedInstanceState) {
//    设置全局未捕获异常处理
    Thread.setDefaultUncaughtExceptionHandler(new ExceptionHander());

//    初始化LOGGER 框架
    Logger.addLogAdapter(new AndroidLogAdapter());
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    if (savedInstanceState == null) {
      getSupportFragmentManager()
          .beginTransaction()
          .replace(R.id.root_layout, RageComicListFragment.newInstance(), "rageComicList")
          .commit();
    }
  }

  @Override
  public void onRageComicSelected(int imageResId, String name, String description, String url) {
    final RageComicDetailsFragment detailsFragment =
        RageComicDetailsFragment.newInstance(imageResId, name, description, url);
    getSupportFragmentManager()
        .beginTransaction()
        .replace(R.id.root_layout, detailsFragment, "rageComicDetails")
        .addToBackStack(null)
        .commit();
  }
}
